﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin.master" AutoEventWireup="true"
    ValidateRequest="false" CodeFile="Commercials.aspx.cs" Inherits="Admin_Commercials" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
    <link href="/Contents/file-upload/fileuploader.css" rel="stylesheet" type="text/css">
    <style type="text/css">
        .search-container
        {
            float: none;
        }
        #ScriptTextBox, #ScriptTextBox_parent
        {
            display: inline-block;
        }
    </style>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div style="padding: 15px;">
        <asp:Panel runat="server" ID="CommercialsListPanel">
            <div style="float: right;">
                <a href="Commercials.aspx?cid=0">Add new commercial &raquo;</a>
            </div>
            <h2>
                Commercials</h2>
            <div class="search-container actions">
                <div class="input">
                    Name:
                    <asp:TextBox runat="server" size="30" CssClass="span4" ID="NameTextBox"></asp:TextBox>
                    &nbsp;&nbsp;&nbsp;&nbsp;
                </div>
                <div class="input">
                    Type:
                    <asp:DropDownList runat="server" ID="TypeDropdown">
                        <asp:ListItem Value="0" Text="--- Select ---"></asp:ListItem>
                        <asp:ListItem Value="101" Text="Left 1 150x500"></asp:ListItem>
                        <asp:ListItem Value="102" Text="Left 2 150x150"></asp:ListItem>
                        <asp:ListItem Value="103" Text="Left 3 150x150"></asp:ListItem>
                        <asp:ListItem Value="104" Text="Right 1 150x150"></asp:ListItem>
                        <asp:ListItem Value="105" Text="Right 2 150x150"></asp:ListItem>
                        <asp:ListItem Value="106" Text="Bottom 1003x150"></asp:ListItem>
                        <asp:ListItem Value="107" Text="Test for news"></asp:ListItem>
                    </asp:DropDownList>
                </div>
                &nbsp;
                <asp:Button class="btn primary" runat="server" ID="SearchButton" Text="Search" OnClick="SearchButton_Click" />
                <a href="Commercials.aspx" class="btn">Refresh</a>
            </div>
            <br style="clear: both;" />
            <asp:Repeater runat="server" ID="CommercialsList">
                <HeaderTemplate>
                    <table class="bordered-table zebra-striped">
                        <tr>
                            <th>
                                Name
                            </th>
                            <th>
                                Type
                            </th>
                            <th>
                                Cost
                            </th>
                            <th>
                                Status
                            </th>
                            <th>
                                Actions
                            </th>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td>
                            <asp:Literal runat="server" ID="Literal1" Text='<%#Eval("Name") %>'></asp:Literal>
                        </td>
                        <td>
                            <asp:Literal runat="server" ID="Literal3" Text='<%#Eval("TypeName") %>'></asp:Literal>
                        </td>
                        <%--<td>
                                <asp:Literal runat="server" ID="DateLiteral" Text='<%#Azad.BCL.DatetimeUtility.FormatDate(Eval("CreatedDate"),"D") %>'></asp:Literal>
                            </td>--%>
                        <td>
                            <asp:Literal runat="server" ID="Literal2" Text='<%#Eval("Cost") %>'></asp:Literal>
                        </td>
                        <td>
                            <asp:Literal runat="server" ID="Literal4" Text='<%# Convert.ToString( Eval("IsActive")) == "True" ? "Active" : "Inactive" %>'></asp:Literal>
                        </td>
                        <td>
                            <%--<a href="#">Preview</a> //--%>
                            <asp:HyperLink runat="server" ID="EditCommercialHyperlink" Text="Edit" NavigateUrl='<%#"Commercials.aspx?cid="+Eval("CommercialId") %>'></asp:HyperLink>
                            //
                            <asp:HyperLink runat="server" ID="ActivateHyperlink" data-action='<%# Convert.ToString( Eval("IsActive")) == "True" ? "inactivate" : "activate" %>'
                                CssClass="activate-commercial" NavigateUrl='<%#"#"+Eval("CommercialId") %>' Text='<%# Convert.ToString(Eval("IsActive")) == "True" ? "Inactivate" : "Activate"%>'></asp:HyperLink>
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
            <asp:Panel runat="server" ID="NoCommercialsMessagePanel" CssClass="alert-message warning">
                <%--<a class="close" href="#">×</a>--%>
                <p>
                    There are no commercials against your query. <a href="Commercials.aspx?cid=0">Add new
                        commercial &raquo;</a></p>
            </asp:Panel>
        </asp:Panel>
        <asp:Panel runat="server" ID="AddEditCommercialPanel">
            <h2>
                <asp:Literal ID="EditCommercialHeading" runat="server" Text="Edit"></asp:Literal>
                <asp:Literal ID="AddCommercialHeading" runat="server" Text="Add"></asp:Literal>
                Commercial</h2>
            <asp:Panel runat="server" ID="CommercialsSavedSuccessfullyPanel" CssClass="alert-message success"
                Visible="false">
                <p>
                    Commercials saved successfully. <a href="#">Preview now</a> or <a href="Commercials.aspx?cid=0">
                        Add new commercial</a> or <a href="Commercials.aspx">go back to Commercials</a>.</p>
            </asp:Panel>
            <asp:Panel runat="server" ID="CommercialsSaveErrorPanel" CssClass="alert-message warning"
                Visible="false">
                <p>
                    Name should be different
                </p>
            </asp:Panel>
            <fieldset>
                <asp:ValidationSummary ID="T" runat="server" />
                <div class="clearfix">
                    <label for="CommercialNameTextBox">
                        Name</label>
                    <div class="input">
                        <asp:TextBox runat="server" ID="CommercialNameTextBox" CssClass="large"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" Text="*" ControlToValidate="CommercialNameTextBox"
                            runat="server" ErrorMessage="Name Required"></asp:RequiredFieldValidator>
                    </div>
                </div>
                <!-- /clearfix -->
                <div class="clearfix">
                    <label for="CommercialTypeDropDownList">
                        Type</label>
                    <div class="input">
                        <asp:DropDownList runat="server" ID="CommercialTypeDropDownList">
                            <asp:ListItem Value="0" Text="--- Select ---"></asp:ListItem>
                            <asp:ListItem Value="101" Text="Left 1 150x500"></asp:ListItem>
                            <asp:ListItem Value="102" Text="Left 2 150x150"></asp:ListItem>
                            <asp:ListItem Value="103" Text="Left 3 150x150"></asp:ListItem>
                            <asp:ListItem Value="104" Text="Right 1 150x150"></asp:ListItem>
                            <asp:ListItem Value="105" Text="Right 2 150x150"></asp:ListItem>
                            <asp:ListItem Value="106" Text="Bottom 1003x150"></asp:ListItem>
                            <asp:ListItem Value="107" Text="Test for news"></asp:ListItem>
                        </asp:DropDownList>
                        <asp:RequiredFieldValidator ID="Rfv1" Text="*" runat="server" ControlToValidate="CommercialTypeDropDownList"
                            InitialValue="0" ErrorMessage="Required!" Display="Dynamic" />
                    </div>
                </div>
                <!-- /clearfix -->
                <div class="clearfix">
                    <label for="NameTextBox">
                        Cost</label>
                    <div class="input">
                        <asp:TextBox runat="server" ID="CommercialCost" CssClass="large"></asp:TextBox>
                    </div>
                </div>
                <!-- /clearfix -->
                <div class="clearfix">
                    <label for="disabledInput">
                        Script</label>
                    <div class="input">
                        <asp:TextBox runat="server" ID="ScriptTextBox" Rows="5" CssClass="xxlarge tinyMCESmall"
                            TextMode="MultiLine"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" Text="*" ControlToValidate="ScriptTextBox"
                            runat="server" ErrorMessage="Script Required"></asp:RequiredFieldValidator>
                        <a class="btn" style="vertical-align: top;" data-controls-modal="upload-image-modal"
                            data-backdrop="static">Upload an image</a>
                    </div>
                </div>
                <!-- /clearfix -->
                <div class="actions">
                    <asp:Button runat="server" ID="SaveCommercialButton" CssClass="btn primary" Text="Save"
                        OnClick="SaveCommercialButton_Click" />
                    &nbsp; <a href="Commercials.aspx" class="btn">Cancel</a>
                </div>
            </fieldset>
            <a href="Commercials.aspx">&laquo; Back to Commercials</a>
        </asp:Panel>
    </div>
    <div id="upload-image-modal" class="modal hide fade" style="display: none;">
        <div class="modal-header">
            <a href="#" class="close">×</a>
            <h3>
                Upload Image</h3>
        </div>
        <div class="modal-body">
            <div id="file-uploader">
                <noscript>
                    <p>
                        Please enable JavaScript to use file uploader.</p>
                    <!-- or put a simple form for upload here -->
                </noscript>
            </div>
            <div id="file-upload-resut">
            </div>
        </div>
        <%--<div class="modal-footer">
    <a href="#" class="btn primary">Primary</a>
    <a href="#" class="btn secondary">Secondary</a>
</div>--%>
    </div>
    <script type="text/javascript" src="/Contents/file-upload/fileuploader.js"></script>
    <script type="text/javascript" src="/Contents/bootstrap-modal.js"></script>
    <script type="text/javascript" src="/Contents/tiny_mce/tiny_mce.js"></script>
    <script type="text/javascript">
        $('.activate-commercial').click(function () {

            var anchor = $(this);
            var cid = anchor.attr('href').replace('#', '');
            var action = anchor.attr('data-action');

            $.getJSON('/Handlers/CommercialsHandler.ashx', { "cid": cid, "action": action, "t": new Date().getTime() }, function (d) {

                if (d) {
                    anchor.attr('data-action', action == "activate" ? "inactivate" : "activate");
                    anchor.html(action == "activate" ? "Inactivate" : "Activate");
                    anchor.parent().prev().html(action == "activate" ? "Active" : "Inactive");
                }

            });

        });
        var Commerial = true;


        $(function () {
            var uploader = new qq.FileUploader({
                element: document.getElementById('file-uploader'),
                action: '/Handlers/UploadHandler.ashx',
                debug: true,

                allowedExtensions: ["png", "gif", "jpg"],
                onComplete: function (id, fileName, responseJSON) {

                    //                    console.log(responseJSON);

                    var resultDiv = document.getElementById('file-upload-resut');
                    //                    var url = window.location.origin + "/documents/CustomImages/" + fileName;

                    resultDiv.innerHTML = "File has been uploaded successfully, copy the url below and start using <br><br>"; //+ url;
                }
            });
        });
    </script>
    <script type="text/javascript">
        tinyMCE.init({
            // General options
            force_br_newlines: true,
            force_p_newlines: false,
            forced_root_block: '',
            mode: "textareas",
            theme: "advanced",
            editor_selector: "tinyMCESmall",
            plugins: "style,table,advimage,advlink,inlinepopups,preview,contextmenu,paste,directionality,noneditable,xhtmlxtras,template,advlist,imgmap",

            // Theme options
            theme_advanced_buttons1: "fontselect,fontsizeselect,|,bold,italic,underline,strikethrough,|,forecolor,backcolor,|,justifyleft,justifycenter,justifyright,justifyfull,|,bullist,numlist,|,outdent,indent",
            theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,removeformat,|,undo,redo,|,link,unlink,anchor,image,|,code,|,preview",
            theme_advanced_buttons3: "imgmap",
            theme_advanced_toolbar_location: "top",
            theme_advanced_toolbar_align: "left",
            theme_advanced_statusbar_location: "bottom",
            theme_advanced_resizing: false,

            extended_valid_elements: "img[usemap|class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],map[id|name],area[shape|alt|coords|href|target],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style],p[lang]",
            // Example content CSS (should be your site CSS)
            content_css: "/Contents/tiny_mce/content.css",

            // Drop lists for link/image/media/template dialogs
            template_external_list_url: "/Contents/tiny_mce/lists/template_list.js",
            external_link_list_url: "/Contents/tiny_mce/lists/link_list.js",
            external_image_list_url: "/Contents/tiny_mce/lists/image_list.js",
            media_external_list_url: "/Contents/tiny_mce/lists/media_list.js"
        });
        function CopyToClipboard(arg) {
            $(arg).zclip({
                path: "/Contents/ZeroClipboard.swf",
                copy: function () {
                    return this.title;
                },
                afterCopy: function () {
                    alert('The url has been copied to your clipboard.');
                }
            });

            return false;
        }
    </script>
</asp:Content>
